package cn.hengzhu.main_manager.utils.xcx;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import cn.hengzhu.main_manager.utils.Base64Util;
import cn.hengzhu.main_manager.utils.Md5Util;
import cn.hengzhu.main_manager.utils.config.xcx.WxConfig;

public class AES256Utils {

	private static final String ALGORITHM = "AES";

	private static final String ALGORITHM_MODE_PADDING = "AES/ECB/PKCS5Padding";

	/**
	 * 生成key
	 */
	private static SecretKeySpec key = new SecretKeySpec(Md5Util.wxXcxHash(WxConfig.KEY).toLowerCase().getBytes(),
			ALGORITHM);

	/**
	 * AES解密
	 * 
	 * @param base64Data
	 * @return
	 * @throws Exception
	 */

	public static String decryptData(String base64Data) throws Exception {
		Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
		cipher.init(Cipher.DECRYPT_MODE, key);
		return new String(cipher.doFinal(Base64Util.decode(base64Data)));
	}

}
